package com.zhxs.utils;

import android.os.Environment;

import com.google.gson.Gson;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class SDCardUtil {
    public static String loadAPNameFromSDFile() {
        String wifiName = "";
        String path = Environment.getExternalStorageDirectory().getPath() + "/SmartService/wifiName.txt";
        File file = new File(path);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdir();
        }
        try {
            int length = (int) file.length();
            byte[] buff = new byte[length];
            FileInputStream fin = new FileInputStream(file);
            fin.read(buff);
            fin.close();
            wifiName = new String(buff, "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return wifiName;
    }

    public static boolean loadWifiTypeFromSDFile() {
        String result = "";
        String path = Environment.getExternalStorageDirectory().getPath() + "/SmartService/wifitype.txt";
        File file = new File(path);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdir();
        }
        try {

            int length = (int) file.length();
            byte[] buff = new byte[length];
            FileInputStream fin = new FileInputStream(file);
            fin.read(buff);
            fin.close();
            result = new String(buff, "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
            try {
                FileOutputStream output = new FileOutputStream(path);
                result = "1";
                output.write(result.getBytes());
            } catch (IOException e1) {

            }
        }
        if ("1".equals(result)) {
            return true;
        } else {
            return false;
        }
    }

}

